<%@ page import="model.Address, java.util.LinkedList" language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:useBean id="subject" scope="request" type="model.subjects.Subject"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Aadressid</title>
</head>
<body>
<div id="addresses">
<h1>Aadressid</h1>
<form>

<% 
//TODO: Kontrollida, kas muudetavad väärtused üldse lähevad kaasa kui value niimoodi tagis juba määratud.
//VB anda aadressitüübi õigeks määramiseks kaasa terve Person/Enterprise vms?
LinkedList<Address> addresses = subject.getAddresses();
for(Address a: addresses){
	out.println("<div class=\"address\">");
	if(a.getAddressType() == 1){
		out.println("<h2>Põhiaadress</h2><br/>");
	}else if(a.getAddressType() == 2){
		out.println("<h2>Lisa-aadress</h2><br/>");
	}else if(a.getAddressType() == 3){
		out.println("<h2>Ettevõtte põhiaadress</h2><br/>"); //Ehk juriidiline aadress
	}
	out.println("<input name=\"id\" value=\""+a.getAddressId()+"\" style=\"display:none\">");
	out.println("<label>Tänav, maja, korterinumber: </label><input name=\"street_address\" value=\"" + a.getStreet_address()+"\"><br/>");
	out.println("<label>Linn/küla: </label><input name=\"town_village\" value=\"" + a.getTown_village()+"\"><br/>");
	out.println("<label>Maakond: </label><input name=\"county\" value=\"" + a.getCounty()+"\"><br/>");
	out.println("<label>Riik: </label><input name=\"country\" value=\"" + a.getCountry()+"\"><br/>");
	out.println("<label>Posti-indeks: </label><input name=\"zipcode\" value=\"" + a.getZipcode()+"\"><br/>");
	out.println("<input type=\"button\" value=\"Tee põhiaadressiks\" action=\"make_primary_address("+a.getAddressId()+","+subject.getSubjectType()+")\">"); //Või teha hoopis checkbox?

	out.println("</div><br/>");
}
%>
<input type="submit" value="Muuda"><input type="button" value="Lisa aadress">

</form>
</div>
</body>
</html>